package com.ht.dsp;

import com.ht.aems.ntp.CIMConstants;
import com.ht.aems.ntp.CIMDataUpdator;
import org.apache.log4j.Logger;
import rtdb.cim.CimKeys;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2008-9-16
 */
public class DspCimListener implements com.ht.aems.ntp.CIMUpdateListener, CIMConstants, CimKeys {
    private static Logger log = Logger.getLogger(DspCimListener.class);

    private CIMDataUpdator updator;

    public DspCimListener(CIMDataUpdator updator) {
        this.updator = updator;
    }

    public void newCIMFileFound() {
        updator.update();
    }

    public void beforeUpdate() {
    }

    public void afterUpdate() {
        if (!updator.isUpdateSuccess())
            return;
        log.info("updating cim resource to rtdb...");
        try {
            RtdbRefresher.saveCimIndexToRtdb(updator.getDir() + File.separator + updator.getFileName());
            log.info("update cim resource to rtdb finished.");
        } catch (Exception e) {
            e.printStackTrace();
            log.warn("Exception occur when saving cim resource to rtdb: " + e);
        }
        //updateGenMeasure();
        //updateArea();
    }
}
